{% if table.foreignKeys.length > 0 %}
-- Foreign keys for table '{{ table.name }}'
{% for foreignKey in table.foreignKeys %}
ALTER TABLE `{{ table.name }}`
  ADD CONSTRAINT {{ foreignKey.name }}
  FOREIGN KEY ({{ foreignKey.columns.replace(r/,\s*/g, ', ') }})
  REFERENCES {{ foreignKey.refTable }}({{ foreignKey.refColumns.replace(r/\s*/g, '').replaceAll(',', ', ') }}){{ " " + foreignKey.options if foreignKey.options }};
{% endfor %}

{% endif %}
